package com.cheng.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

/**
 * 读取properties配置文件
 */
public class LoadProperties {
    public static void main(String[] args) {
        try (
                InputStream inputStream = new FileInputStream("io/resources/jdbc.properties");
        ) {
            Properties properties = new Properties();
            // 自动读取配置文件中的K-V
            properties.load(inputStream);

            //获取所有key
            Enumeration<?> enumeration = properties.propertyNames();
            while (enumeration.hasMoreElements()) {
                String name = (String)enumeration.nextElement();
                //获取value
                String value = properties.getProperty(name);
                System.out.println(name + "=" + value);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
